package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.domain.AnswerComment;
import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.mapper.AnswerCommentMapper;
import cn.wolfcode.trip.base.mapper.AnswerMapper;
import cn.wolfcode.trip.base.query.AnswerCommentQueryObject;
import cn.wolfcode.trip.base.query.AnswerQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAnswerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AnswerServiceImpl implements IAnswerService{
    @Autowired
    private AnswerMapper answerMapper;
    @Autowired
    private AnswerCommentMapper answerCommentMapper;

    public PageInfo listAll(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<Answer> list = answerMapper.selectForList(qo);
        return new PageInfo<Answer>(list);
    }

    public void save(Answer answer) {
        //设置创建时间
        answer.setCreateTime(new Date());
        answerMapper.insert(answer);
    }

    public Answer getById(Long answerId) {
        return answerMapper.selectByPrimaryKey(answerId);
    }

    public void saveByAnswerId(AnswerComment answerComment) {
        answerCommentMapper.insert(answerComment);
    }

    public void updateCommentCount(int commentCount, Long answerId) {
        answerMapper.updateByAnswerId(commentCount,answerId);
    }


    public List<AnswerComment> getCommentByAnswerId(Long answerId) {
        return answerCommentMapper.selectAll(answerId);
    }
}
